package ynu.lcy.service.impl;


import org.springframework.stereotype.Service;
import ynu.lcy.dao.ITypeDao;

import ynu.lcy.dto.business.AddOrderTypeRequestDTO;
import ynu.lcy.elememicroserviceserviceclient.service.FileUploadFeignClient;
import ynu.lcy.entity.OrderType;
import ynu.lcy.service.OrderTypeService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class OrderTypeServiceImpl implements OrderTypeService {
    @Resource
    private ITypeDao dao;

    @Resource
    private FileUploadFeignClient fileUploadFeignClient;

    /**
     * 获取全部点餐类型
     * @return
     */
    public List<OrderType> list(){
        return dao.findAll();
    }

    /**
     * 添加类型
     * @param dto dto
     * */
    public OrderType add(AddOrderTypeRequestDTO dto){
        String file = fileUploadFeignClient.upload(dto);
        OrderType orderType = new OrderType();
        orderType.setLabel(dto.getLabel());
        orderType.setCreateTime(new Date());
        orderType.setImage(file);
        return dao.save(orderType);
    }
}
